﻿using System;
using System.Collections.Generic;
using System.Text;
using EmbeddedSharp.Core;
using EmbeddedSharp.Scripting.Function;

namespace EmbeddedSharp.Scripting
{
    public class ShellFunctionManager : DefaultFunctionManager
    {
        /// <summary>
        /// Clone a equvilent function
        /// </summary>
        /// <param name="funcNode"></param>
        /// <returns></returns>
        public UserDefinedFunctionNode Clone(
            UserDefinedFunctionNode funcNode)
        {
            UserDefinedFunctionNode clone
                = new UserDefinedFunctionNode();
            UserDefinedFunctionNode template
                = funcNode as UserDefinedFunctionNode;

            clone.Name = template.Name;
            clone.Arguments
                = new string[template.Arguments.Length];
            for (
                int index = 0;
                index < template.Arguments.Length; index++)
            {
                clone.Parameters[index]
                    = template.Parameters[index];
            }

            clone.Precedence = template.Precedence;
            clone.LineNumber = template.LineNumber;
            clone.Value = template.Value;
            clone.Comment = template.Comment;
            clone.ClassName = template.ClassName;
            clone.Body = template.Body;
            clone.FuncBody = template.FuncBody;
            clone.ParserFactory = template.ParserFactory;
            clone.FunctionManager = this;

            return clone;
        }

    }
}
